﻿using System;
using GeoAPI.Geometries;

namespace NetTopologySuite.Noding
{
	public static class Octant
	{
		public static Octants GetOctant(double dx, double dy)
		{
			if (dx == 0.0 && dy == 0.0)
			{
				throw new ArgumentException(string.Concat(new object[]
				{
					"Cannot compute the octant for point ( ",
					dx,
					", ",
					dy,
					" )"
				}));
			}
			double num = System.Math.Abs(dx);
			double num2 = System.Math.Abs(dy);
			if (dx >= 0.0)
			{
				if (dy >= 0.0)
				{
					if (num >= num2)
					{
						return Octants.Zero;
					}
					return Octants.One;
				}
				else
				{
					if (num >= num2)
					{
						return Octants.Seven;
					}
					return Octants.Six;
				}
			}
			else if (dy >= 0.0)
			{
				if (num >= num2)
				{
					return Octants.Three;
				}
				return Octants.Two;
			}
			else
			{
				if (num >= num2)
				{
					return Octants.Four;
				}
				return Octants.Five;
			}
		}

		public static Octants GetOctant(Coordinate p0, Coordinate p1)
		{
			double num = p1.X - p0.X;
			double num2 = p1.Y - p0.Y;
			if (num == 0.0 && num2 == 0.0)
			{
				throw new ArgumentException("Cannot compute the octant for two identical points " + p0);
			}
			return Octant.GetOctant(num, num2);
		}
	}
}
